﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using frag_boardgame;

namespace Website.BoardWebControl
{
    public partial class ShootButton : System.Web.UI.UserControl
    {
        Player player;
        
        public delegate void tryShootDelegate (int playerID);
        public event tryShootDelegate OnTryShoot;

        public void UpdateTargetSquare(Player player)
        {
            this.player = player;
            if (player == null)
            {
                this.targetLable.Text = "No Target";
                this.targetID.Value = "";
            }
            else
            {
                this.targetLable.Text = player.Name;
                this.targetID.Value = player.ID.ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void hitButton_Click(object sender, ImageClickEventArgs e)
        {
            if (!targetID.Value.Equals("") )
            {
                try
                {
                    int id;
                    int.TryParse(  targetID.Value,out id);
                    OnTryShoot(id);
                }
                catch(Exception ex)
                {
                }

                
            }
            else
            {
                targetLable.Text = "No Target";
                
            }
        }


    }
}